package org.webrtc.mqttclientsample;

import org.json.JSONException;
import org.json.JSONObject;

public class MessageBuilder {
	
	public static Message build(String data){
		Message message = new Message();
		try {
			JSONObject jsonObj = new JSONObject(data);
			String from = jsonObj.getString("from");
			String to = jsonObj.getString("to");
			String content = jsonObj.getString("content");
			String type = jsonObj.getString("type");
			message.setFrom(from);
			message.setTo(to);
			message.setContent(content);
			message.setType(Message.MessageType.valueOf(type));
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			
		}
		return message;
	}

}
